/**************** STUDY 2 ****************/

* Authoritarian Reforms and External Legitimacy, by Calvert W. Jones

* Using Stata/MP 17. Please call up Study2_Data from the appropriate directory.


* Use appropriate directory
import delimited "...\Study2_Data", varnames(1) case(preserve) 


* Prepare attributes for conjoint analysis (oil duplicative of wealth and therefore excluded, see Appendix B)

encode conservative, gen(attribute_conservative)
encode wealth, gen(attribute_wealth)
encode govtype, gen(attribute_govtype)
encode tourism, gen(attribute_tourism)
encode ally, gen(attribute_ally)
encode critics, gen(attribute_critics)
encode reform, gen(attribute_reform)
encode experts, gen(attribute_experts)
encode nationality, gen(attribute_nationality)
encode response, gen(attribute_response)


gen anyReform=.
replace anyReform=0 if reform=="control"
replace anyReform=1 if reform=="climate change" | reform=="education reform" | reform=="religious tolerance" | reform=="social freedoms" | reform=="tolerance ministry" | reform=="women's rights"



* Generate/label DVs

label define favorableLabels 1 "Very unfavorable" 2 "Unfavorable" 3 "Somewhat unfavorable" 4 "Neutral" 5 "Somewhat favorable" 6 "Favorable" 7 "Very favorable"
encode fav, gen(num_fav) label(favorableLabels)
encode trade, gen(num_trade) label(favorableLabels)
encode cut, gen(num_cut) label(favorableLabels)
encode boycott, gen(num_boycott) label(favorableLabels)
encode visit, gen(num_visit) label(favorableLabels)

label var num_fav "Favorability"
label var num_trade "Trade"
label var num_cut "Cutting off relations"
label var num_boycott "Boycott"


/* Stata's default baselines are alphabetical as follows
attribute_conservative
1 somewhat liberal 2 very conservative
baseline 1

attribute_wealth
1 not very 2 very
baseline 1

attribute_govtype
1 a military dictatorship 2 a monarchy, ruled by a king and royal family 3 autocratic, led by a single political party
baseline 1

attribute_tourism (deveopment)
1 modern airport, good hotels and restaurants, and a striking natural landscape 2 small airport, some inexpensive hotels, and beautiful landscapes
baseline 2

attribute_ally (geopolitical value)
1 a US ally, with a strong trade relationship 2 not an ally of the United States, with a weak trade relationship
baseline 2

attribute_critics (depth of autocracy)
1 not a democracy 2 not a democracy, lacks a free press, and denies civil liberties to many citizens
baseline 1

attribute_reform
1 climate change 2 control 3 education reform 4 religious tolerance 5 social freedoms 6 tolerance ministry 7 women's rights 
baseline 2

attribute_experts (technocratic)
1 experts 2 the ruler
baseline 2

attribute_nationality
1 American 2 Chinese 3 international 4 local
baseline 4

attribute_response
1 positive/neutral response 2 skeptical response
baseline 1
*/


/* Re-order attribute levels for some attributes so that they appear in a more natural order within figures */ 


* Development - make "low" the baseline
gen attribute_tourismR=.
replace attribute_tourismR=1 if attribute_tourism==2	  
replace attribute_tourismR=2 if attribute_tourism==1
* To check: browse attribute_tourism attribute_tourismR
* Now, 1=low and 2=high

* Geopolitical value (ally) - make "not a US ally" the baseline  
gen attribute_allyR=.
replace attribute_allyR=1 if attribute_ally==2	  
replace attribute_allyR=2 if attribute_ally==1
* To check: browse attribute_ally attribute_allyR
* Now, 1=not a US ally (low geopolitical value) and 2=US ally (high geopolitical value)

* Reform - Make "no reform" the baseline of 1, and also change the order to match Study 1's presentation for ease of readability across studies

gen attribute_reformR=.
replace attribute_reformR=1 if attribute_reform==2
replace attribute_reformR=2 if attribute_reform==7
replace attribute_reformR=3 if attribute_reform==4
replace attribute_reformR=4 if attribute_reform==5
replace attribute_reformR=5 if attribute_reform==3
replace attribute_reformR=6 if attribute_reform==6
replace attribute_reformR=7 if attribute_reform==1
* To check: browse attribute_reform attribute_reformR
* Now, 1=no reform, 2=women's rights, 3=religious moderation, 4=Civil freedom, 5=liberal ed; 6=social tolerance; 7=environment/climate change

* Technocratic/experts - make "the ruler" (non-technocratic, or no experts involved) the baseline
gen attribute_expertsR=.
replace attribute_expertsR=1 if attribute_experts==2
replace attribute_expertsR=2 if attribute_experts==1
* To check: browse attribute_experts attribute_expertsR
* Now, 1=no experts involved ("the ruler") and 2=experts involved


/* Label attributes, including reordered ones */

label var attribute_conservative "Culture"
label define attribute_conservative_values 1 "Somewhat liberal" 2 "Very conservative"
label values attribute_conservative attribute_conservative_values 

label var attribute_wealth "Wealth" 
label define attribute_wealth_values 1 "Low" 2 "High"
label values attribute_wealth attribute_wealth_values 

label var attribute_govtype "Type of government"
label define attribute_govtype_values 1 "Military dictatorship" 2 "Authoritarian monarchy" 3 "Single party dominant"
label values attribute_govtype attribute_govtype_values 

* Note this is a variable with reordered attribute levels (R at the end for "reordered")
label var attribute_tourismR "Economic development"
label define attribute_tourismR_values 1 "Low" 2 "High"
label values attribute_tourismR attribute_tourismR_values 
 
* Likewise, this is a variable with reordered attribute levels (R at the end for "reordered")
label var attribute_allyR "Geopolitical value"
label define attribute_allyR_values 1 "Not a US ally" 2 "US ally"
label values attribute_allyR attribute_allyR_values 

label var attribute_critics "Depth of autocracy"
label define attribute_critics_values 1 "Autocracy" 2 "Repressive autocracy" 
label values attribute_critics attribute_critics_values 

* Another attribute with reordered levels (R at the end for "reordered")
label var attribute_reformR "Reform type"
label define attribute_reformR_values 1 "No reform" 2 "Women's rights" 3 "Religious moderation" 4 "Civil freedom" 5 "Liberal education" 6 "Social tolerance" 7 "Environment/climate change"
label values attribute_reformR attribute_reformR_values 

* Last attribute with reordered levels (R at the end for "reordered")
label var attribute_expertsR "Technocratic"
label define attribute_expertsR_values 1 "No experts" 2 "Experts involved" 
label values attribute_expertsR  attribute_expertsR_values 

label var attribute_nationality "Expert nationality"
label define attribute_nationality_values 1 "American" 2 "Chinese" 3 "International" 4 "Local"
label values attribute_nationality attribute_nationality_values 


label var attribute_response "Observers' response"
label define attribute_response_values 1 "Neutral" 2 "Skeptical"
label values attribute_response attribute_response_values 

label var anyReform "Reform"
label define anyReform_values 0 "No reform" 1 "Reform"
label values anyReform anyReform_values


/* Analysis */

** Favorability

* Using anyReform vs. control (no reform)
regress num_fav i.anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store fav_any

* Using all individual reforms vs. control (no reform)
regress num_fav i.attribute_reformR i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store fav_all

** Trade with country

* Using anyReform vs. control (no reform)
regress num_trade i.anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store trade_any

* Using all individual reforms vs. control (no reform)
regress num_trade i.attribute_reformR i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store trade_all


** Cut off relations

* Using anyReform vs. control (no reform)
regress num_cut i.anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store cut_any

* Using all individual reforms vs. control (no reform)
regress num_cut i.attribute_reformR i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store cut_all

** Boycott

* Using anyReform vs. control (no reform)
regress num_boycott i.anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR  i.attribute_critics, cluster(ResponseId)
estimates store boycott_any

* Using all individual reforms vs. control (no reform)
regress num_boycott i.attribute_reformR i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)
estimates store boycott_all


*** Create Figure 5 in manuscript (shows AMCEs for anyReform and all individual reforms)

coefplot (fav_any, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_any, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_any, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_any, msymbol(D) mcolor(black) label("Boycott") offset(-.3)) (fav_all, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_all, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_all, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_all, msymbol(D) mcolor(black) label("Boycott") offset(-.3)), keep(*.anyReform *.attribute_reformR) headings(0.anyReform="{bf:Any Reform vs. Control}" 1.attribute_reformR="{bf:Individual Reforms vs. Control}") xline(0, lcolor(black))  baselevels drop(_cons) levels(95 90) graphregion(color(white)) bgcolor(white) lcolor(black) ciopts(color(black black)) xscale(range(-.6 .6)) scale(.7) aspect(2) legend(order(3 6 9 12) col(1) position(3))

* Generate tables
esttab fav_any trade_any cut_any boycott_any, label keep (*.anyReform) se
esttab fav_all trade_all cut_all boycott_all, label keep(*.attribute_reformR) se


*** Create Figure 6 in manuscript (shows AMCEs of all attributes)

coefplot (fav_all, msymbol(O) mcolor(black) label("Favorability") offset(.4)) (trade_all, msymbol(S) mcolor(black) label("Trade") offset(.1)) (cut_all, msymbol(T) mcolor(black) label("Cut off relations") offset(-.2)) (boycott_all, msymbol(D) mcolor(black) label("Boycott") offset(-.45)), headings(1.attribute_reformR="{bf:Reform}" 1.attribute_govtype="{bf:Government type}" 1.attribute_allyR="{bf:Geopolitical value}" 1.attribute_conservative="{bf:Culture}" 1.attribute_wealth="{bf:Wealth}" 1.attribute_tourismR="{bf:Economic development}" 1.attribute_critics="{bf:Depth of autocracy}", labsize(large)) xline(0, lcolor(black))  baselevels drop(_cons) levels(95 90) graphregion(color(white)) bgcolor(white) lcolor(black) ciopts(color(black black)) legend(col(1)) xscale(range(-.6 .6)) xsize(15) ysize(30) scale(.7) coeflabels(, labsize(large))

* Generates table (all AMCEs)
esttab fav_all trade_all cut_all boycott_all, label se



*** Create Figure 7 in manuscript (shows AMCEs of all attributes)
/* Note: This figure reports subconjoint AMCEs -- i.e., analysis is conducted only over authoritarian regimes undergoing reform, and the "no reform" control group is excluded. */


* Subconjoint analysis generating AMCEs of technocratic involvement (experts involved in reform), response to the reform (neutral/critical)

regress num_fav i.attribute_expertsR i.attribute_response if reform!="control", cluster(ResponseId)
estimates store fav_sub

regress num_trade i.attribute_expertsR i.attribute_response if reform!="control", cluster(ResponseId)
estimates store trade_sub

regress num_cut i.attribute_expertsR i.attribute_response if reform!="control", cluster(ResponseId)
estimates store cut_sub

regress num_boycott i.attribute_expertsR i.attribute_response if reform!="control", cluster(ResponseId)
estimates store boycott_sub


* Subconjoint analysis limiting expert nationality to Americans only

regress num_fav i.attribute_reformR i.attribute_expertsR i.attribute_response if reform!="control" & nationality!="international" & nationality!="Chinese" & nationality!="local", cluster(ResponseId)
estimates store fav_subonlyA

regress num_trade i.attribute_reformR i.attribute_expertsR i.attribute_response if reform!="control" & nationality!="international" & nationality!="Chinese" & nationality!="local", cluster(ResponseId)
estimates store trade_subonlyA

regress num_cut i.attribute_reformR i.attribute_expertsR i.attribute_response if reform!="control" & nationality!="international" & nationality!="Chinese" & nationality!="local", cluster(ResponseId)
estimates store cut_subonlyA

regress num_boycott i.attribute_reformR i.attribute_expertsR i.attribute_response if reform!="control" & nationality!="international" & nationality!="Chinese" & nationality!="local", cluster(ResponseId)
estimates store boycott_subonlyA

/* Create Figure 7 in manuscript, showing subconjoint AMCES.*/

coefplot (fav_sub, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_sub, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_sub, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_sub, msymbol(D) mcolor(black) label("Boycott") offset(-.3)), bylabel("All expert nationalities") keep(*.attribute_expertsR *.attribute_response) || (fav_subonlyA, msymbol(O) mcolor(black) label("Favorability") offset(.3)) (trade_subonlyA, msymbol(S) mcolor(black) label("Trade with country") offset(.1)) (cut_subonlyA, msymbol(T) mcolor(black) label("Cut off relations") offset(-.1)) (boycott_subonlyA, msymbol(D) mcolor(black) label("Boycott") offset(-.3)), bylabel("Limit to American experts") keep(*.attribute_expertsR) ||, headings(1.attribute_expertsR="{bf:Technocratic}" 1.attribute_response="{bf:Observers' response}") xline(0, lcolor(black))  baselevels drop(_cons) levels(95 90) graphregion(color(white)) plotregion(color(white)) bgcolor(white) lcolor(black) ciopts(color(black black)) legend(col(1)) xscale(range(-.4 .4)) scheme(s1mono)

* Generate tables
esttab fav_sub trade_sub cut_sub boycott_sub, label se keep(*.attribute_expertsR *.attribute_response)
esttab fav_subonlyA trade_subonlyA cut_subonlyA boycott_subonlyA, label se keep(*.attribute_expertsR)


** Testing H2 (supported) - "Positive benefits will be stronger than shielding benefits."

* Create index for positive/participatory benefits

egen fav_trade_index = rowmean(num_fav num_trade)

* Create index for shielding benefits (use absolute values)

egen cut_boycott_index = rowmean(num_cut num_boycott)

* Convert shielding benefits index to an index using absolute values; we need to compare the absolute value/size of coefficients so that higher scores indicate greater benefits. 

gen num_cut_rec = num_cut 
recode num_cut_rec (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)
gen num_boycott_rec = num_boycott 
recode num_boycott_rec (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1)

egen cb_index_rec = rowmean(num_cut_rec num_boycott_rec)

* Run regression using positive benefits index (note clustering is done at the end)
regress fav_trade_index anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics
estimates store ft_index_results_nc

* Run regression using shielding benefits index (clustering at end)
regress cb_index_rec anyReform i.attribute_govtype i.attribute_allyR i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics
estimates store cb_index_res_rec_nc

* Use seemingly unrelated estimation (suest) - clustering is performed here
suest ft_index_results_nc cb_index_res_rec_nc, cluster(ResponseId)

test [ft_index_results_nc_mean]anyReform - [cb_index_res_rec_nc_mean]anyReform = 0

lincom [ft_index_results_nc_mean]anyReform - [cb_index_res_rec_nc_mean]anyReform


** Testing H6 (some limited support for geopolitical value)

** Low vs. high geopolitical value (AMCE differences by geopolitical value)

* Favorability (not supported - no differences across levels of geopolitical value)
regress num_fav i.anyReform##i.attribute_allyR i.attribute_govtype i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_allyR
lincom 1.anyReform#1.attribute_allyR - 1.anyReform#2.attribute_allyR
margins attribute_allyR, dydx(anyReform)
margins attribute_allyR, dydx(anyReform) pwcompare(effects)

* Trade (supported - non-allies benefit more)
regress num_trade i.anyReform##i.attribute_allyR i.attribute_govtype i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_allyR
lincom 1.anyReform#1.attribute_allyR - 1.anyReform#2.attribute_allyR
margins attribute_allyR, dydx(anyReform)
margins attribute_allyR, dydx(anyReform) pwcompare(effects)

* Cut relations (not supported - no differences across levels of geopolitical value)
regress num_cut i.anyReform##i.attribute_allyR i.attribute_govtype i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_allyR
lincom 1.anyReform#1.attribute_allyR - 1.anyReform#2.attribute_allyR
margins attribute_allyR, dydx(anyReform)
margins attribute_allyR, dydx(anyReform) pwcompare(effects)

* Boycott (supported - non-allies benefit more)
regress num_boycott i.anyReform##i.attribute_allyR i.attribute_govtype i.attribute_conservative i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_allyR
lincom 1.anyReform#1.attribute_allyR - 1.anyReform#2.attribute_allyR
margins attribute_allyR, dydx(anyReform)
margins attribute_allyR, dydx(anyReform) pwcompare(effects)

** Relatively liberal vs. very conservative (AMCE differences by culture)

* Favorability (not supported - no differences across levels of culture variable)
regress num_fav i.anyReform##i.attribute_conservative i.attribute_allyR i.attribute_govtype i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_conservative
lincom 1.anyReform#1.attribute_conservative - 1.anyReform#2.attribute_conservative
margins attribute_conservative, dydx(anyReform)
margins attribute_conservative, dydx(anyReform) pwcompare(effects)

* Trade (not supported - no differences across levels of culture variable)
regress num_trade i.anyReform##i.attribute_conservative i.attribute_allyR i.attribute_govtype i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_conservative
lincom 1.anyReform#1.attribute_conservative - 1.anyReform#2.attribute_conservative
margins attribute_conservative, dydx(anyReform)
margins attribute_conservative, dydx(anyReform) pwcompare(effects)

* Cut off relations (not supported - no differences across levels of culture variable)
regress num_cut i.anyReform##i.attribute_conservative i.attribute_allyR i.attribute_govtype i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_conservative
lincom 1.anyReform#1.attribute_conservative - 1.anyReform#2.attribute_conservative
margins attribute_conservative, dydx(anyReform)
margins attribute_conservative, dydx(anyReform) pwcompare(effects)

* Boycott (not supported - no differences across levels of culture variable)
regress num_boycott i.anyReform##i.attribute_conservative i.attribute_allyR i.attribute_govtype i.attribute_wealth i.attribute_tourismR i.attribute_critics, cluster(ResponseId)

testparm i.anyReform#i.attribute_conservative
lincom 1.anyReform#1.attribute_conservative - 1.anyReform#2.attribute_conservative
margins attribute_conservative, dydx(anyReform)
margins attribute_conservative, dydx(anyReform) pwcompare(effects)



